import Taro, {Component} from '@tarojs/taro'
import {View, Text, Input,Button} from '@tarojs/components'
import './authorityDialog.scss'
import Dialog from "../../common/components/dialog";


/**
 * 当前房产弹窗
 */

type PageState = {
    name: string,
    company: string,
}

type Props = {
    onCloseDialog: Function;
    onSubmitClick: Function;
    onGetUserInfo: Function;
    getUserInfoCallBack: Function;
}


class AuthorityDialog extends Component<Props, PageState> {

    constructor(props) {
        super(props);
        this.state = {
            name: '',
            company: '',
        }
    }


    onConfirm() {
        let {name, company} = this.state;
        if(!name){
          Taro.showToast({title: '申请名字不能为空！', icon: 'none'});
          return
        }
        if(!company){
          Taro.showToast({title: '申请公司名称不能为空！', icon: 'none'});
          return;
        }
        this.props.onSubmitClick && this.props.onSubmitClick(name,company);
    }

    onCloseDialog() {
        this.props.onCloseDialog && this.props.onCloseDialog();
    }

    onNameInput(e) {
        this.setState({
            name: e.detail.value
        })
    }

    onCompanyInput(e) {
        this.setState({
          company: e.detail.value
        })
    }

    onGetUserInfo(){
        this.props.onGetUserInfo && this.props.onGetUserInfo();
    }
    getUserInfoCallBack(){
        this.props.getUserInfoCallBack && this.props.getUserInfoCallBack();
    }

    render() {
        let {name, company} = this.state;
        return (
            <Dialog>
                <View className='edit_pop_content' catchtouchmove='true'>
                    <View className='local_pop_body'>
                        <Text className='title'>权限申请</Text>
                        <View className='user-info-content'>
                            <View className='top-empty'/>
                            <View className='item-content'>
                                <Text className='title-input'>姓</Text>
                                <Text className='title-input-s'>名</Text>
                                <Input
                                    value={name}
                                    className='name-input'
                                    placeholder={'请输入姓名'}
                                    onInput={this.onNameInput.bind(this)}
                                    placeholderStyle={'font-weight: 400; color: #999999; font-size: 28rpx; line-height: 28rpx;'}
                                />
                            </View>
                            <View className='item-content'>
                                <Text className='title-input-x'>公司名称</Text>
                                <Input
                                    value={company}
                                    className='name-input'
                                    placeholder={'请输入公司名称'}
                                    onInput={this.onCompanyInput.bind(this)}
                                    placeholderStyle={'font-weight: 400; color: #999999; font-size: 28rpx; line-height: 28rpx;'}
                                />
                            </View>
                            <View className='bottom-empty'/>
                        </View>
                        <View className='btn_content'>
                            <Text className='btn_cancel' onClick={this.onCloseDialog.bind(this)}>取消</Text>
                            <Button className='opacityBtn' onClick={this.onConfirm.bind(this)}>
                            <Text className='btn_confirm' onClick={this.onConfirm.bind(this)}>提交申请</Text>
                            </Button>
                        </View>
                    </View>
                </View>
            </Dialog>
        )
    }
}


export default AuthorityDialog
